#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    int fd = open("Data.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
    
    dup2(fd,1);
    printf("hello worldlalalalal\n");


    //close(1);
    //int fd = open("Data.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
    //printf("hello world\n");
    //fprintf(stdout,"hello world\n");
    

    //int fd = open("Data.txt",O_RDONLY);
    //int a = 0;
    //scanf("%d",&a);
    //printf("%d\n",a);
    /*
    umask(0);
    int fd = open("Data.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
    int fd = open("Data.txt",O_WRONLY|O_CREAT|O_APPEND,0666);
    if(fd == -1)
    {
        perror("open fail");
        return 1;
    }

    const char * str = "hello world\n";
    write(fd,str,strlen(str));

    close(fd);
    */
    return 0;
}




/*
#define ONE 1
#define TWO (1 << 1)
#define THREE (1 << 2)
#define FOUR (1 << 3)
#define FIVE (1 << 4)


void print(int flag)
{
    if(flag & ONE) printf("1\n");
    if(flag & TWO) printf("2\n");
    if(flag & THREE) printf("3\n");
    if(flag & FOUR) printf("4\n");
    if(flag & FIVE) printf("5\n");
}

int main()
{
    print(ONE);
    printf("__________________________________\n");
    print(TWO);
    printf("__________________________________\n");
    print(ONE|TWO);
    printf("__________________________________\n");
    print(THREE|FOUR|FIVE);
    printf("__________________________________\n");
    print(ONE|TWO|THREE|FOUR|FIVE);

    
    return 0;
}

*/

/*
int main()
{
    FILE* fp = fopen("Data.txt","r");
    if(fp == NULL)
    {
        perror("fopen fila");
        return 1;
    }
    
    char buffer[64];

    while(1)
    {
        char *r = fgets(buffer,sizeof(buffer),fp);
        if(r == NULL) break;
        else printf("%s",buffer);

    }


    const char* msg = "hello world\n";
    
    int cnt = 5;

    while(cnt--)
    {
        int n = fwrite(msg,strlen(msg),1,fp);
        printf("write %d block,pid is: %d\n",n,getpid());
        sleep(20);
    }
    
    fclose(fp);
    return 0;
}
*/
